package rw.rwbehaviour;

/**
 * 二维坐标
 *
 * @author RW daze
 */
public class Vector2 {
    public float x = 0;

    public float y = 0;

    public Vector2() {
    }

    public Vector2(float x, float y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 计算两个点之间的距离
     *
     * @param target 另外一个点
     * @return 两点之间的距离
     */
    public float distance(Vector2 target) {
        float x1 = target.x - this.x;
        float y1 = target.y - this.y;
        return (float) Math.sqrt(x1 * x1 + y1 * y1);
    }

    /**
     * 计算两个点之间的距离
     *
     * @param from 起点
     * @param to   终点
     * @return 两点之间的距离
     */
    public static float getDistance(Vector2 from, Vector2 to) {
        float x1 = from.x - to.x;
        float y1 = from.y - to.y;
        return (float) Math.sqrt(x1 * x1 + y1 * y1);
    }
}
